import edu.cqie.dao.UserDao1;
import edu.cqie.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import org.apache.ibatis.io.Resources;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.InputStream;
import java.io.IOException;
import java.util.List;

/**
 * Mytest
 *
 * @description:
 * @Author XiaoZhou
 * @Date 2023/10/17 22:58
 */
public class Mytest {
    @Test
    public void test() throws IOException {
        String resources = "mybatis-config.xml";
        InputStream in = Resources.getResourceAsStream(resources);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(in);
        SqlSession sqlSession = sessionFactory.openSession(true);
        UserDao1 mapper = sqlSession.getMapper(UserDao1.class);
        List<User> users = mapper.selectUser();
        for (User user : users) {
            System.out.println(user);
        }
    }

    @Test
    public void test1() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        UserDao1 userMapper = context.getBean("userMapper2", UserDao1.class);
        for (User user : userMapper.selectUser()) {
            System.out.println(user);
        }
    }
}
